
local LoginCtrl={}

local isNewPlayer=false

function LoginCtrl:init()
    print("LoginCtrl init")
    NetEngine:registerCallback(ProtoCmd.ResToCreateRoleMessage,function(msg)
        isNewPlayer=true
        RoleData.player_info.uid = msg.uid
        FzEventCenter:DispichEvent(FzEvent.CreatePlayer)
    end)
    NetEngine:registerCallback(ProtoCmd.ResCreateRoleMessage,function(msg)
        RoleData.player_info.name = msg.rolename
        RoleData.player_info.rid = msg.rid
        --NetEngine:sendMessage(ProtoCmd.ReqEnterGameMessage,{uid=RoleData.player_info.uid,rid=RoleData.player_info.rid})
    end)
    NetEngine:registerCallback(ProtoCmd.ResEnterGameMessage,function(msg)
        

        RoleData.player_info.rid=msg.rid
        RoleData.player_info.stageid=msg.stageid
        RoleData.player_info.pos.x=msg.x
        RoleData.player_info.pos.y=msg.y
        RoleData.curtime=msg.curtime
        RoleData.startupTime=msg.startupTime
        ServerTime.setTime(msg.curtime/1000)
        FzEventCenter:DispichEvent(FzEvent.LoginSuccess)
        --NetEngine:startHeartBeat()
    end)
    NetEngine:registerCallback(ProtoCmd.ResEnterStageMessage,function(msg)
        ModelsManager:requestInit()
        DyActor:addProtoActors(msg.actor,true)
        FzEventCenter:DispichEvent(FzEvent.addActors)
    end)
    NetEngine:registerCallback(ProtoCmd.ResSystemDataMessage,function(msg)
        if msg.param.lastDayLogins then
            RoleData.lastDayLogins = msg.param.lastDayLogins
        end
    end)
    NetEngine:registerCallback(ProtoCmd.ResKickMessage,function(msg)
        Alert:show("title_kick_off","msg_kick_off",Alert.TYPE_OK,function()
            MyApp:restart()
        end)
    end)
end

function LoginCtrl:clean()
    NetEngine:unregisterCallback(ProtoCmd.ResToCreateRoleMessage)
    NetEngine:unregisterCallback(ProtoCmd.ResCreateRoleMessage)
    NetEngine:unregisterCallback(ProtoCmd.ResEnterGameMessage) 
    NetEngine:unregisterCallback(ProtoCmd.ResEnterStageMessage)
    NetEngine:unregisterCallback(ProtoCmd.ResSystemDataMessage)
    NetEngine:unregisterCallback(ProtoCmd.ResKickMessage)
end

return LoginCtrl